﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XQ.RequestOfficeSupplies.DAL.DAL
{
   public class Sys_DepartmentsDal
    {
        private RequestOfficeSuppliesEntities ce;
        //获取部门
        public List<Sys_Departments> GetDepartment()
        {
            List<Sys_Departments> list = new List<Sys_Departments>();
            using (DataContext db = new DataContext())
            {
                string sql = "SELECT * FROM Sys_Departments WHERE LEN(Code) =12";
                list = db.Database.SqlQuery<Sys_Departments>(sql).ToList();
            }
            return list;
        }

        /// <summary>
        /// 获取部门列表(二级部门)
        /// </summary>
        /// <returns></returns>
        public List<Sys_Departments> GetDepartments()
        {
            List<Sys_Departments> list = new List<Sys_Departments>();
            using (DataContext db = new DataContext())
            {
                string sql = "SELECT * FROM Sys_Departments WHERE parentID =1";
                list = db.Database.SqlQuery<Sys_Departments>(sql).ToList();
            }
            return list;
        }

        public List<Sys_Departments> GetDepartmentId(int InfoID)
        {
            List<Sys_Departments> list = new List<Sys_Departments>();
            using (ce = new RequestOfficeSuppliesEntities())
            {
                var sql = @"select * from Sys_Departments sd inner join  Enterprise_DetailInfo ed  on ed.Id =" + InfoID + " and ed.DepartmentId =sd.ID ";
                list = ce.Database.SqlQuery<Sys_Departments>(sql.ToString()).ToList();
            }

            return list;
        }


        //获取行业门类
        public List<Sys_Departments> GetPianqu()
        {
            List<Sys_Departments> list = new List<Sys_Departments>();
            using (DataContext db = new DataContext())
            {
                string sql = "SELECT * FROM Sys_Departments WHERE Code LIKE'PQ%'";
                list = db.Database.SqlQuery<Sys_Departments>(sql).ToList();
            }
            return list;
        }
        //获取片区下拉的值
        public List<Sys_Departments> GetPianquId(int InfoID)
        {
            List<Sys_Departments> list = new List<Sys_Departments>();
            using (ce = new RequestOfficeSuppliesEntities())
            {

                var sql = @"select * from Sys_Departments sd inner join  Enterprise_DetailInfo ed  on ed.Id =" + InfoID + " and ed.PianquId =sd.ID ";

                list = ce.Database.SqlQuery<Sys_Departments>(sql.ToString()).ToList();
            }

            return list;
        }

    }
}
